package org.contato.standalone;

import org.contato.entity.Usuario;
import org.contato.service.UsuarioService;
import org.sharkness.remoting.service.AuthRemoteService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class HttpInvokerTestConnection {

	public static void main(String[] args) throws Exception {
		
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
			"/org/contato/standalone/context.xml"
		);
		
		AuthRemoteService authRemoteService = ctx.getBean(AuthRemoteService.class);

		Object obj = authRemoteService.login("admin", "123");
		
		if (obj instanceof Authentication) {
			Authentication authentication = (Authentication)obj; 
			if (authentication != null) {
				SecurityContextHolder.getContext().setAuthentication(authentication);
			}
		}
		
		UsuarioService usuarioService = ctx.getBean(UsuarioService.class);
		System.out.println(usuarioService);
		for (Usuario u : usuarioService.list()) {
			System.out.println(u);
		}
		
	}

}
